Public Sub TraceRay(ByVal direct_calculation As Boolean, ByVal depth As Integer, ByVal skip_object As RayTraceable, ByVal px As Single, ByVal py As Single, ByVal pz As Single, ByVal Vx As Single, ByVal Vy As Single, ByVal Vz As Single, ByRef R As Integer, ByRef G As Integer, ByRef B As Integer)
Dim obj As RayTraceable
Dim best_obj As RayTraceable
Dim best_t As Single
Dim t As Single
' Find the object that's closest.
best_t = INFINITY
For Each obj In Objects
' Skip the object skip_object. We use this
' to avoid erroneously hitting the object
' casting out a ray.
If Not (obj Is skip_object) Then
t = obj.FindT(direct_calculation, px, py, pz, Vx, Vy, Vz)
If (t > 0) And (best_t > t) Then
best_t = t
Set best_obj = obj
End If
End If
Next obj
' See if we hit anything.
If best_obj Is Nothing Then
' We hit nothing. Return the background color.
R = BackR
G = BackG
B = BackB
Else
' Compute the color at that point.
best_obj.FindHitColor depth, Objects, _
px, py, pz, _
px + best_t * Vx, _
py + best_t * Vy, _
pz + best_t * Vz, _
R, G, B
' This is a problem for some values of Kdist.
If R < 0 Then R = 0
If G < 0 Then G = 0
If B < 0 Then B = 0
End If
End Sub
' Ray trace on this picture box.
Public Sub TraceAllRays(ByVal pic As PictureBox, ByVal skip As Integer, ByVal depth As Integer)